/*
 * flash.h
 */
#ifndef __FLASH_H
#define __FLASH_H

#include "stdint.h"
#include "debug.h"

#define FLASH_SAVE_LEN (256)         // for ch32v003,FLASH_SAVE_LEN % 64 == 0
#define FLASH_SAVE_ADDR (0x08003F00) // for ch32v003,FLASH_SAVE_ADDR % 64 == 0
#define FLASH_ERASED_WORD (0xFFFFFFFF)
#define flash_read32(addr) (*(uint32_t *)(addr))
#define flash_empty() (flash_read32(FLASH_SAVE_ADDR + HREG2BUF(HREG_ADDR) * 2) == FLASH_ERASED_WORD)
void flash_save_parameters(uint16_t *data);
void flash_load_parameters(uint16_t *data);

#endif
